<?php
class IndexAction extends PublicAction {
	
    public function index(){
    	$citycode = session('citycode','');
    	if(!$citycode){
	    	$citycode = $this->getPosition('114.07', '22.62');//根据地理坐标获取城市代码
	    	//echo $citycode;die;
	    	$citycode =$citycode?$citycode: C('SITE_INFO')['citycode'];	//城市代码
	    	//var_dump($citycode['citycode']);die;
	    	session('citycode',$citycode);
    	}
    	
    	$this->cname = M('city')->where(array('code'=>$citycode))->field('name')->find()['name'];
    	//获取分类
		$category = D('CategoryView')->getAllc(array('cd.language_id'=>L('lan_id'),'c.categories_status'=>1),'c.sort_order asc');
		/* echo "<pre>";
		var_dump($category);die;  */
		//获取商品
		$productlist = D('Products')->getProductsList(array('products_close'=>0,'products_status'=>1,'show_flag'=>0,'recommend'=>1,'citycode'=>$citycode),'sort_order asc,products_id desc','0,3');
		//echo "<pre>";var_dump($productlist);die;
		//获取站内前十条公告
		$news = D('News')->getListByField(array('n.news_status'=>1,'ni.news_language_id'=>L('lan_id')),'0,10','n.top_flag desc,n.sort_order asc,n.news_id desc','n.news_id,ni.news_title');
		//var_dump($news);die;
		//获取首页banner
		$banners = M('banner')->where(array('banner_status'=>1))->field('banner_image,banner_id')->order('sort_order desc')->select();
		//var_dump($banners);die;
		$this->banners = $banners;
		$this->category = $category;
		$this->productlist = $productlist;
		$this->news = $news;
		$this->display();
	}
	
	
}